/**
 * Created by dukes on 2016/3/5.
 */
class SearchGuildPanel extends eui.Component{
    public callObj:any=null;
    public okBack:Function=null;
    public cancelBack:Function=null;
    public constructor(){
        super();
        this.skinName = "skins.scene.SearchGuildSkin";
    }
    private img_close:eui.Image;
    private name_input:eui.TextInput;
    private img_search:eui.Image;
    public partAdded(name:string, instance:any) {
        super.partAdded(name, instance);
        if (name == "img_close") {
            this.img_close = instance;
            this.img_close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
        } else if (name == "name_input") {
            this.name_input = instance;
        }else  if( name == "img_search"){
            this.img_search = instance;
            this.img_search.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onOk, this);
        }
    }

    private onClose(evt:egret.TouchEvent){
        SoundMgr.getInstance().playEffect(SoundMgr.BTN);
        DisplayController.instance().removeFromAlert(GameConst.GrayMask);
        DisplayController.instance().removeFromAlert(this);
    }

    private onOk(evt:egret.TouchEvent){
        DisplayController.instance().removeFromAlert(GameConst.GrayMask);
        DisplayController.instance().removeFromAlert(this);
        var id = parseInt(this.name_input.text);
        if( id ){
            window["__guildList"](1,id);
        }
        else
            ShowHint("请输入要查找的ID");
    }

    public show(){
        DisplayController.instance().addToAlert(GameConst.GrayMask);
        DisplayController.instance().addToAlert(this);
    }

    public measure(){
        super.measure();
        this.x = GameConst.StageW - this.measuredWidth >> 1;
        this.y = GameConst.StageH - this.measuredHeight >> 1;
    }

    private static _instance:SearchGuildPanel;
    public static getInstance():SearchGuildPanel{
        if( SearchGuildPanel._instance == null )
            SearchGuildPanel._instance = new SearchGuildPanel();
        return SearchGuildPanel._instance;
    }
}